package com.spa;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.TimeZone;

import javax.annotation.PostConstruct;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.spa.common.utils.oConvertUtils;

import lombok.extern.slf4j.Slf4j;

@EnableTransactionManagement // 开启注解事务管理，等同于xml配置文件中的 <tx:annotation-driven />
@EnableScheduling // 定时任务
@SpringBootApplication
@Slf4j
public class Application {

	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
		
		// 设置显示的swagger环境信息
        Profiles profiles = Profiles.of("dev", "test");
        Environment environment = application.getEnvironment();
        // 判断是否处在自己设定的环境当中
		boolean flag = environment.acceptsProfiles(profiles);
        if(flag) {
        	
    		String ip = InetAddress.getLocalHost().getHostAddress();
    		String port = environment.getProperty("server.port");
    		String path = oConvertUtils.getString(environment.getProperty("server.servlet.context-path"));
    		log.info("\n----------------------------------------------------------\n\t"
    				+ "Application siemens-esp is running! Access URLs:\n\t" + "Local: \t\thttp://localhost:" + port + path
    				+ "/\n\t" + "External: \thttp://" + ip + ":" + port + path + "/\n\t" + "Swagger文档: \thttp://" + ip + ":"
    				+ port + path + "/doc.html\n"
    				+ "----------------------------------------------------------");
        }
	}

	@PostConstruct
	void started() {
		TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
	}
}
